package xin.marcher.module.common.message;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import xin.marcher.module.common.constants.RocketMqConstant;

import java.io.Serializable;
import java.util.List;

/**
 * 数据变更消息体
 */
@Data
public class DataChangeMessage implements Serializable {

    /**
     * 内部消息编号
     */
    private String messageNo;

    /**
     * 操作行为，INSERT、UPDATE、DELETE
     */
    private String action;

    /**
     * 表名
     */
    private String tableName;

    /**
     * 主键或业务id
     */
    private Object keyId;

    /**
     * 变更的列
     */
    private List<String> updateColumns;

    /**
     * 唯一确定当前数据的字段以及字段值
     */
    private List<ColumnValue> columnValues;

    /**
     * 消息处理成功之后的回调topic
     */
    private String callbackTopic = RocketMqConstant.DATA_EXTERNAL_CHANGE_TOPIC;

    public DataChangeMessage(String operateType, String tableName, List<String> updateColumns) {
        this.action = operateType;
        this.tableName = tableName;
        this.updateColumns = updateColumns;
    }


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ColumnValue {

        /**
         * 列
         */
        private String column;

        /**
         * 值
         */
        private Object value;
    }
}